package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.User;
import com.zr.service.DistributionRangePriceServiceLPN;
import com.zr.service.OrderServiceLPN;

import net.sf.json.JSONObject;

public class OrderActionLPN extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{
	private HttpServletRequest req;
	private HttpServletResponse resp;
	private Map<String, Object> session;
	private int page;
	private int rows;
	private int orId;
    private String orDeliveryDate;   
    private String otName;
    private String orState ;
    private String orRemarks;
    private String orSenderName;
    private String orSenderPhone;
    private String orSenderCompanyPhone ;
    private String orSenderAddr;  
    private String orRecipientName ;
    private String orRecipientPhone  ;
    private String orRecipientCompanyPhone;
    private String orRecipientAddr;
    private Double orCargoWeight;
    private Double orCargoVolume;
    private String orItemName ;
    private String orItemNumber;
    private String  cyName  ;
    private Double orInsuredValue ; 
    private Double orPostage;
    private Double orTotalCost;
    private String orPaymentMethod  ;
    private String orIssuanceDate  ;
    private String dpNamef;
    private String  dpNames ;
    private String csCurrentLocation;
    private String customerName ;
    private String eiName;
	private String orIds;
	
	
    
    public String getOrIds() {
		return orIds;
	}

	public void setOrIds(String orIds) {
		this.orIds = orIds;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public HttpServletRequest getReq() {
		return req;
	}

	public void setReq(HttpServletRequest req) {
		this.req = req;
	}

	public HttpServletResponse getResp() {
		return resp;
	}

	public void setResp(HttpServletResponse resp) {
		this.resp = resp;
	}

	public int getOrId() {
		return orId;
	}

	public void setOrId(int orId) {
		this.orId = orId;
	}

	public String getOrDeliveryDate() {
		return orDeliveryDate;
	}

	public void setOrDeliveryDate(String orDeliveryDate) {
		this.orDeliveryDate = orDeliveryDate;
	}

	public String getOtName() {
		return otName;
	}

	public void setOtName(String otName) {
		this.otName = otName;
	}

	public String getOrState() {
		return orState;
	}

	public void setOrState(String orState) {
		this.orState = orState;
	}

	public String getOrRemarks() {
		return orRemarks;
	}

	public void setOrRemarks(String orRemarks) {
		this.orRemarks = orRemarks;
	}

	public String getOrSenderName() {
		return orSenderName;
	}

	public void setOrSenderName(String orSenderName) {
		this.orSenderName = orSenderName;
	}

	public String getOrSenderPhone() {
		return orSenderPhone;
	}

	public void setOrSenderPhone(String orSenderPhone) {
		this.orSenderPhone = orSenderPhone;
	}

	public String getOrSenderCompanyPhone() {
		return orSenderCompanyPhone;
	}

	public void setOrSenderCompanyPhone(String orSenderCompanyPhone) {
		this.orSenderCompanyPhone = orSenderCompanyPhone;
	}

	public String getOrSenderAddr() {
		return orSenderAddr;
	}

	public void setOrSenderAddr(String orSenderAddr) {
		this.orSenderAddr = orSenderAddr;
	}

	public String getOrRecipientName() {
		return orRecipientName;
	}

	public void setOrRecipientName(String orRecipientName) {
		this.orRecipientName = orRecipientName;
	}

	public String getOrRecipientPhone() {
		return orRecipientPhone;
	}

	public void setOrRecipientPhone(String orRecipientPhone) {
		this.orRecipientPhone = orRecipientPhone;
	}

	public String getOrRecipientCompanyPhone() {
		return orRecipientCompanyPhone;
	}

	public void setOrRecipientCompanyPhone(String orRecipientCompanyPhone) {
		this.orRecipientCompanyPhone = orRecipientCompanyPhone;
	}

	public String getOrRecipientAddr() {
		return orRecipientAddr;
	}

	public void setOrRecipientAddr(String orRecipientAddr) {
		this.orRecipientAddr = orRecipientAddr;
	}

	

	public String getOrItemName() {
		return orItemName;
	}

	public void setOrItemName(String orItemName) {
		this.orItemName = orItemName;
	}

	public String getOrItemNumber() {
		return orItemNumber;
	}

	public void setOrItemNumber(String orItemNumber) {
		this.orItemNumber = orItemNumber;
	}

	public String getCyName() {
		return cyName;
	}

	public void setCyName(String cyName) {
		this.cyName = cyName;
	}

	


	public Double getOrCargoWeight() {
		return orCargoWeight;
	}

	public void setOrCargoWeight(Double orCargoWeight) {
		this.orCargoWeight = orCargoWeight;
	}

	public Double getOrCargoVolume() {
		return orCargoVolume;
	}

	public void setOrCargoVolume(Double orCargoVolume) {
		this.orCargoVolume = orCargoVolume;
	}

	public Double getOrInsuredValue() {
		return orInsuredValue;
	}

	public void setOrInsuredValue(Double orInsuredValue) {
		this.orInsuredValue = orInsuredValue;
	}

	public Double getOrPostage() {
		return orPostage;
	}

	public void setOrPostage(Double orPostage) {
		this.orPostage = orPostage;
	}

	public Double getOrTotalCost() {
		return orTotalCost;
	}

	public void setOrTotalCost(Double orTotalCost) {
		this.orTotalCost = orTotalCost;
	}

	public OrderServiceLPN getOrs() {
		return ors;
	}

	public void setOrs(OrderServiceLPN ors) {
		this.ors = ors;
	}

	public String getOrPaymentMethod() {
		return orPaymentMethod;
	}

	public void setOrPaymentMethod(String orPaymentMethod) {
		this.orPaymentMethod = orPaymentMethod;
	}

	public String getOrIssuanceDate() {
		return orIssuanceDate;
	}

	public void setOrIssuanceDate(String orIssuanceDate) {
		this.orIssuanceDate = orIssuanceDate;
	}

	public String getDpNamef() {
		return dpNamef;
	}

	public void setDpNamef(String dpNamef) {
		this.dpNamef = dpNamef;
	}

	public String getDpNames() {
		return dpNames;
	}

	public void setDpNames(String dpNames) {
		this.dpNames = dpNames;
	}

	public String getCsCurrentLocation() {
		return csCurrentLocation;
	}

	public void setCsCurrentLocation(String csCurrentLocation) {
		this.csCurrentLocation = csCurrentLocation;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getEiName() {
		return eiName;
	}

	public void setEiName(String eiName) {
		this.eiName = eiName;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	
	//属性注入
			@Resource
			private OrderServiceLPN ors;
			
			
		/**
		 * 得到订单信息	
		 * @throws IOException
		 */
	public void getOrder() throws IOException{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		
		JSONObject j = ors.findOrder(page, rows);
		
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
    }
	
	
	/**
	 * 得到未发货订单信息	
	 * @throws IOException
	 */
	public void getOrderByState() throws IOException{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String orState = "未发货";
		JSONObject j = ors.getOrderByState(page, rows, orState);
		
		PrintWriter pw = resp.getWriter();
		pw.write(j.toString());
		pw.flush();
		pw.close();
	}
	
	
	
	
	
	
	/**
	 * 修改订单信息
	 * @throws IOException 
	 */
	public void updateOR() throws IOException{
		PrintWriter  pw = resp.getWriter();
		
		String[] orIdsArr = orIds.split(",");
		int j = 0;
		for (int i = 0; i < orIdsArr.length; i++) {
			int orId1 = Integer.parseInt(orIdsArr[i]);
			 j = ors.updateOR(orId1, orState);
			 System.out.println(j);
		}
		if (j>0) {
			pw.write("1");
		} else {
			pw.write("0");
		}
		
	}
	
	
	
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.resp=arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.req=arg0;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session=arg0;
	}

}
